package com.eduhzy.ttw.clazz.mvp.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.widget.LinearLayout;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.blankj.utilcode.util.SPUtils;
import com.eduhzy.ttw.clazz.R;
import com.eduhzy.ttw.clazz.R2;
import com.eduhzy.ttw.clazz.mvp.model.entity.HomeData;
import com.eduhzy.ttw.clazz.mvp.ui.fragment.ClazzReportFragment;
import com.eduhzy.ttw.commonres.utils.RxUtil;
import com.eduhzy.ttw.commonsdk.adapter.HomeFragmentAdapter;
import com.eduhzy.ttw.commonsdk.core.Constants;
import com.eduhzy.ttw.commonsdk.core.RouterHub;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.mvp.IView;
import com.jess.arms.utils.ArmsUtils;
import com.qmuiteam.qmui.widget.dialog.QMUITipDialog;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;

import static com.jess.arms.utils.Preconditions.checkNotNull;

/**
 * @author xubo
 * @date 2018-12-7 10:35:33
 */
@Route(path = RouterHub.CLAZZ_CLAZZREPORTACTIVITY)
public class ClazzReportActivity extends BaseActivity implements IView {
    @Autowired(name = Constants.PARCELABLE_DATA)
    HomeData mBean;


    @BindView(R2.id.tabs)
    TabLayout tabs;
    @BindView(R2.id.viewpager)
    ViewPager viewpager;

    List<Fragment> mFragments;

    String[] mTitles = new String[]{
            SPUtils.getInstance().getString(Constants.USERNICKNAME), "全部"
    };

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        //如找不到该类,请编译一下项目
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        MobclickAgent.onEvent(getActivity(),"ttw_class_report");
        //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
        return R.layout.clazz_activity_clazz_report;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mFragments = new ArrayList<>();
        setDivider();
        ClazzReportFragment self = ClazzReportFragment.newInstance(mBean, 1);
        mFragments.add(self);
        ClazzReportFragment all = ClazzReportFragment.newInstance(mBean, 2);
        mFragments.add(all);
        HomeFragmentAdapter adapter = new HomeFragmentAdapter(getSupportFragmentManager(), Arrays.asList(mTitles), mFragments);
        viewpager.setAdapter(adapter);
        viewpager.setOffscreenPageLimit(mTitles.length);
        tabs.setupWithViewPager(viewpager);
    }

    private void setDivider() {
        /*TabLayout中间分界线*/
        LinearLayout linearLayout = (LinearLayout) tabs.getChildAt(0);
        linearLayout.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        linearLayout.setDividerDrawable(ContextCompat.getDrawable(this,
                R.drawable.layout_divider_vertical));
        linearLayout.setDividerPadding(RxUtil.getAutoHeight(getActivity(), 20));
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        RxUtil.showTipDialog(getActivity(), QMUITipDialog.Builder.ICON_TYPE_NOTHING, message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    public Activity getActivity() {
        return this;
    }
}
